package com.tcs.test.print;

import com.google.common.collect.Maps;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedHashMap;
import java.util.Set;

public class PrintThree {

    private final Logger logger = LoggerFactory.getLogger(PrintThree.class);

    private LinkedHashMap<String,Integer> map = Maps.newLinkedHashMap();

    @Test
    public void print() {
        String bianLiang = "xxxdyyys";
        StringBuffer sb = new StringBuffer(bianLiang.length());
        char[] charArray = bianLiang.toCharArray();
        int count = 0;
        for (int i = 0; i < charArray.length; i++) {
            if (bianLiang.lastIndexOf(charArray[i]) > -1) {
                logger.info("str: {} ,indexOf: {} " , charArray[i] , bianLiang.lastIndexOf(charArray[i]));
                put(charArray[i]+"");
            }
        }
        Set<String> set = map.keySet();
        for (String str : set) {
            if (map.get(str) > 1) {
                sb.append(map.get(str));
            }
            sb.append(str);
        }
        logger.info("map: {} , str : {}" , map , sb.toString());
    }

    public void put(String key) {
        if (map.containsKey(key)) {
            map.put(key ,map.get(key) + 1);
        } else {
            map.put(key,1);
        }
    }
}
